package cn.ezios.huo.s3.old;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectResponse;

import java.io.File;
import java.net.URI;

public class UseS3 {
    static String accessKey = "SRvUfCthAu0NgrvoWWKp";
    static String secretKey = "J8N5GTQXyTNEYovoIfaaAf63jZKFWDn3KDXAyiol";
    static String endpoint = "http://127.0.0.1:9000"; // 例如：http://localhost:9000
    static String bucketName = "sxln";

    public static void main(String[] args) {

        S3Client s3Client = S3Client.builder()
                .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
                .region(Region.CN_NORTHWEST_1)
                .endpointOverride(URI.create(endpoint))
                .build();
//        System.out.println(s3Client.listBuckets().toString());
//        s3Client.putObject(PutObjectRequest.builder().bucket(bucketName).key("test.txt").build(), RequestBody.empty());
        PutObjectResponse response = s3Client.putObject(p -> p.bucket(bucketName).key("test.txt").build(), RequestBody.fromFile(new File("d:/docker-compose.yml")));

    }
}
